import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:playtruly/common/routers/pages.dart';

/// 路由服务
class RouteService extends GetxService {
  // 单例模式
  static RouteService get to => Get.find<RouteService>();
  
  // 获取当前路由
  String? get currentRoute => RoutePages.currentRoute;
  
  // 获取上一个路由
  String? get previousRoute => RoutePages.previousRoute;
  
  // 获取路由历史
  List<String> get history => RoutePages.history;
  
  // 返回上一页
  void goBack() {
    Get.back();
  }
  
  // 返回到指定页面
  void goBackTo(String routeName) {
    Get.until((route) => route.settings.name == routeName);
  }
  
  // 返回到首页
  void goBackToHome() {
    Get.offAllNamed(RoutePages.history.first);
  }
  
  // 打印路由历史
  void printRouteHistory() {
    debugPrint('当前路由历史: ${RoutePages.history}');
    debugPrint('当前路由: ${RoutePages.currentRoute}');
    debugPrint('上一个路由: ${RoutePages.previousRoute}');
  }
  
  // 清空路由历史
  void clearHistory() {
    RoutePages.clearHistory();
  }
} 